/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.qdu.servlet;

import com.qdu.entity.PublicActivity;
import com.qdu.service.impl.PublicActivityServiceImpl;
import java.io.IOException;
import java.text.ParseException;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.qdu.service.PublicActivityService;

/**
 *
 * @author Daniel
 */
@WebServlet("/spas")
public class SubmitPublicActivityServlet extends HttpServlet {
    PublicActivityService ps = new PublicActivityServiceImpl();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        

       
        
        req.setCharacterEncoding("utf-8");
        int Pno = Integer.parseInt(req.getParameter("Pno"));
        String Ptopic = req.getParameter("Ptopic");
        String Ptype = req.getParameter("Ptype");
        int Pnum = 1;
        String Pbstart = req.getParameter ( "Pbstart" );
        SimpleDateFormat mat1 = new SimpleDateFormat ( "yyyy-MM-dd" );
        Date md1 = null;
        try {
            md1 = mat1.parse ( Pbstart );
        } catch (ParseException e) {
            e.printStackTrace ();
        }
        String Pbend = req.getParameter ("Pbend");
        SimpleDateFormat mat2 = new SimpleDateFormat ( "yyyy-MM-dd" );
        Date md2 = null;
        try {
            md2 = mat2.parse ( Pbend );
        } catch (ParseException e) {
            e.printStackTrace ();
        }
        String Pbegin = req.getParameter ("Pbegin");
        SimpleDateFormat mat3 = new SimpleDateFormat ( "yyyy-MM-dd" );
        Date md3 = null;
        try {
            md3 = mat3.parse (Pbegin);
        } catch (ParseException e) {
            e.printStackTrace ();
        }
        String Pend = req.getParameter ( "Pend" );
        SimpleDateFormat mat4 = new SimpleDateFormat ( "yyyy-MM-dd" );
        Date md4 = null;
        try {
            md4 = mat4.parse(Pend);
        } catch (ParseException e) {
            e.printStackTrace ();
        }
        int Pmoney = Integer.parseInt(req.getParameter("Pmoney"));
        String Plocal = req.getParameter("Plocal");
        String Pintro = req.getParameter("Pintro");
        String Pps = req.getParameter("Pps");
        String Ptag = req.getParameter("Ptag");
        String Psit = req.getParameter("Psit");
        int Uno = Integer.parseInt(req.getParameter("Uno"));
        

        PublicActivity newPublic = new PublicActivity( Pno,Ptopic, Ptype, Pnum, md1, md2, md3, md4, Pmoney, Plocal,Pintro,  Pps,  Ptag, Psit,Uno);
        int rows =  ps.submitNewPublic(newPublic);
     
        resp.getWriter().println(rows);
    }
}
